home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
vesa_tsr.zip
/
SAMPLES
/
VESAPCX.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1990-10-05
|
24KB
|
864 lines
{-----------------------------------------------------------------------}
{VESAPCX GL:01/15/90 }
{-----------------------------------------------------------------------}
{Program for decoding a 4-plane or 8-bit PCX file using the facilities }
{defined by the VESA Super VGA BIOS Extensions to provide for using }
{the extended resolutions of a Super VGA card in a hardware independent }
{manner. Zsoft's PCX file format was chosen because of its relative }
{simplicity, so that this demonstration program would not become overly }
{cluttered with image decoding information. PCX is the native file }
{format of Zsoft Paintbrush Plus and other paint programs. }
{-----------------------------------------------------------------------}
{The following program is written to loosely conform to the VESA }
{Super VGA BIOS Extension document VS891001. The program is intended }
{as a demonstration and is not intended to be an example of a }
{high-performance implementations of the VESA standard. }
{ Gary Lorensen }
{ Everex Systems, Inc. }
{ 48571 Milmont Dr. B3 }
{ Fremont, CA 94538 }
{-----------------------------------------------------------------------}
uses
dos;
{-----------------------------------------------------------------------}
const
rSequAddr = $3C4;
{-----------------------------------------------------------------------}
type
ColorType = record
r,g,b : byte;
end;
PCXHeaderType = record
manu : byte; {10d=0Ah= ZSoft PCX}
vers : byte; {0=v2.5,2=v2.8 w/pal,3=v2.8 wo/pal,5=v3.0}
code : byte; {1=PCX run length}
bpp : byte; {bits/pixel/plane}
xmin : word; {image dimensions}
ymin : word;
xmax : word;
ymax : word;
hres : word; {Source device horz res}
vres : word; {Source device vert res}
pal : array [$00..$0F] of ColorType;
res0 : byte; {reserved}
npln : byte; {Number of color planes}
bpl : word; {Bytes/scan/plane (usually even)}
pinf : word; {Palette info (1=color/BW, 2=gray, 9=????)}
dpi : word; {Scanner dpi or VRes}
res1 : array [$00..$37] of byte; {reserved}
end;
ByteBufferPtrType = ^ByteBufferType;
ByteBufferType = array [$00..$00] of byte;
{-----------------------------------------------------------------------}
s80 = string[80];
s8 = string[8];
DacType = array [$00..$FF] of ColorType;
{-----------------------------------------------------------------------}
CharString = array [$00..$03] of char;
ModeListType = array [$00..$00] of word;
PageFuncPtrType = pointer;
VgaInfoBlockType = record
VESASignature : CharString;
VESAVersion : word;
OEMStringPtr : ^CharString;
Capabilities : array [$00..$03] of byte;
VideoModePtr : ^ModeListType;
reserved : array [$00..$ED] of byte; {Pad to 256}
end;
ModeInfoBlockType = record
{mandatory information}
ModeAttributes : word;
WinAAttributes : byte;
WinBAttributes : byte;
WinGranularity : word;
WinSize : word;
WinASegment : word;
WinBSegment : word;
WinFuncPtr : PageFuncPtrType;
BytesPerScanLine : word;
{optional information}
XResolution : word;
YResolution : word;
XCharSize : byte;
YCharSize : byte;
NumberOfPlanes : byte;
BitsPerPixel : byte;
NumberOfBanks : byte;
MemoryModel : byte;
BankSize : byte;
reserved : array [$00..$E2] of byte; {Pad to 256}
end;
{-----------------------------------------------------------------------}
{-----------------------------------------------------------------------}
var
reg : Registers;
VesaVgaInfo : VgaInfoBlockType;
VesaModeInfo : ModeInfoBlockType;
prevVesaMode : word;
VesaMode : word;
PcxHeader : PCXHeaderType;
pcxfile : file;
pcxfname : s80;
i,j : word;
ch : char;
{-----------------------------------------------------------------------}
{-----------------------------------------------------------------------}
function decval(ch : char) : byte;
begin
decval := 0;
if ((ch>='0') and (ch<='9')) then
decval := ord(ch)-ord('0');
if ((ch>='A') and (ch<='F')) then
decval := ord(ch)-ord('A')+$0A;
if ((ch>='a') and (ch<='f')) then
decval := ord(ch)-ord('a')+$0A;
end;
function hex2dec(s : s80) : word;
var
i : byte;
tmp : word;
place : word;
begin
i := ord(s[0]);
place := 1;
tmp := 0;
while (i>0) do begin
tmp := tmp+place*decval(s[i]);
i:=i-1;
place := place*$10;
end;
hex2dec := tmp;
{ writeln('hex2dec(',s,') = ',tmp);}
end;
{-----------------------------------------------------------------------}
function hexval(x : byte) : char;
begin
hexval := '0';
if ((x>=0) and (x<=9)) then
hexval := chr(x+ord('0'));
if ((x>=10) and (x<=15)) then
hexval := chr(x-10+ord('A'));
end;
function dec2hex(x : word) : s8;
var
tmp : s8;
place : word;
begin
{ tmp := '0';}
tmp := ' ';
if (x>=$100) then
place := $1000
else
place := $10;
repeat
tmp := tmp+hexval(x div place);
x := x mod place;
place := place div $10;
until (place=$0000);
dec2hex := tmp+'h';
end;
function hex(x : word) : s8;
var
tmp : s8;
place : word;
begin
tmp := '0';
if (x>=$100) then
place := $1000
else
place := $10;
repeat
tmp := tmp+hexval(x div place);
x := x mod place;
place := place div $10;
until (place=$0000);
hex := tmp+'h';
end;
function addrhex(x : word) : s8;
var
tmp : s8;
place : word;
begin
tmp := '';
place := $1000;
repeat
tmp := tmp+hexval(x div place);
x := x mod place;
place := place div $10;
until (place=$0000);
addrhex := tmp;
end;
{-----------------------------------------------------------------------}
function Min(m,n : longint) : longint;
begin
if (m<n) then
Min := m
else
Min := n;
end;
function Max(m,n : longint) : longint;
begin
if (m>n) then
Max := m
else
Max := n;
end;
{-----------------------------------------------------------------------}
procedure SetVesaBank(win : byte;
bank : byte);
var
reg : Registers;
begin
reg.AX := $4F05;
reg.BH := $00;
reg.BL := win;
reg.DX := bank;
intr($10,reg);
end;
{-----------------------------------------------------------------------}
procedure GetVesaBank(win : byte;
var bank : byte);
var
reg : Registers;
begin
reg.AX := $4F05;
reg.BH := $01;
reg.BL := win;
intr($10,reg);
bank := reg.DX;
end;
{-----------------------------------------------------------------------}
procedure FindVesaMode(xsize,ysize : word;
memmodel : byte;
bitpixel : byte;
var bestVesaMode : word;
var bestVesaModeInfo : ModeInfoBlockType);
var
tmpVesaModeInfo : ModeInfoBlockType;
i : byte;
error : boolean;
begin
i := $00;
bestVesaMode := $FFFF;
error := false;
while ((VesaVgaInfo.VideoModePtr^[i]<>$FFFF) and not(error)) do begin
reg.AX := $4F01;
reg.CX := VesaVgaInfo.VideoModePtr^[i];
reg.ES := Seg(tmpVesaModeInfo);
reg.DI := Ofs(tmpVesaModeInfo);
intr($10,reg);
error := (reg.AX<>$004F);
if (tmpVesaModeInfo.ModeAttributes and $02=$00) then begin
case VesaVgaInfo.VideoModePtr^[i] of
$0100,$0101,$0103,$0105,$0107 : begin
tmpVesaModeInfo.XCharSize := 0;
tmpVesaModeInfo.YCharSize := 0;
tmpVesaModeInfo.NumberOfPlanes:= 1;
tmpVesaModeInfo.BitsPerPixel:= 8;
tmpVesaModeInfo.NumberOfBanks:= 1;
tmpVesaModeInfo.MemoryModel := $04;
tmpVesaModeInfo.BankSize := 0;
end;
$0102,$0104,$0106 : begin
tmpVesaModeInfo.XCharSize := 0;
tmpVesaModeInfo.YCharSize := 0;
tmpVesaModeInfo.Number